<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="layout">
	<tiles:putAttribute name="head">
		<style type="text/css">
.editForm {
	display: none;
}
</style>
		<script type="text/javascript">
			$(function() {
				$(".edit").click(function() {
					var ele = $(this).prev("form");
					art.dialog({
						content : ele.get(0)
					});
				});

				$("form").Validform({
					ajaxPost : true,
					tiptype : ValidUtils.siblingTip,
					callback : function(data) {
						helper.showMsg(data, {
							okHandler : function() {
								location = "listClassroom";
							}
						});
					}
				});

				$(".confirm").confirmDialog(function(data) {
					helper.showMsg(data, {
						okHandler : function() {
							location.reload();
						}
					});
				});
			});
		</script>
	</tiles:putAttribute>
	<tiles:putAttribute name="mainBody">
		<s:set var="c" value="currentCampus" />
		<ul class="breadcrumb">
			<li class="active">教室管理</li>
		</ul>
		<div class="row-fluid">
			<div class="span7">
				<table class="table">
					<thead>
						<tr>
							<th>名称</th>
							<th>校区</th>
							<th>操作</th>
							<th>查看</th>
						</tr>
					</thead>
					<tbody>
						<s:iterator value="classrooms" var="classroom">
							<tr>
								<td>${classroom.name}</td>
								<td>${classroom.campus}</td>
								<td>
									<form class=".form-horizontal editForm" action="doModifyClassroom">
										<input type="hidden" name="id" value="${classroom.id}" />

										<div class="control-group">
											<label class="control-label">教室名称 </label>
											<div class="controls">
												<input type="text" name="name" value="${classroom.name }" />
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">所属校区</label>
											<div class="controls">
												<s:if test="#c == null">
													<select name="campus">
														<s:iterator value="campuses" var="t">
															<option value="${t.id}" <s:if test="#t.id == #classroom.campus.id ">selected="selected"</s:if>>${t.title}</option>
														</s:iterator>
													</select>
												</s:if>
												<s:else>
													<input type="text" value="${c.name}" readonly="readonly" />
													<input type="hidden" name="campus" value="${c.id}" />
												</s:else>
											</div>
										</div>
										<div class="control-group">
											<div class="controls">
												<button class="btn btn-primary" type="submit">修改</button>
											</div>
										</div>
									</form> <a href="javascript:void(0)" class="edit">编辑</a> <s:url action="doRemoveClassroom" namespace="/classroom" id="doRemoveClassroom">
										<s:param name="id" value="id"></s:param>
									</s:url> <a href="${doRemoveClassroom}" class="confirm" title="删除该教室">删除</a>
								</td>
								<td><s:url namespace="/schedule" action="listClassroomLesson" id="listClassroomLesson">
										<s:param name="classroomId" value="id"></s:param>
									</s:url> <a href="${listClassroomLesson}">查看教室课程</a></td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</div>
			<div class="span5">
				<form class="form-horizontal" action="doCreateClassroom">
					<fieldset>
						<legend>新建</legend>
						<div class="control-group">
							<div class="control-label">教室名称</div>
							<div class="controls">
								<input type="text" name="name" />
							</div>
						</div>
						<div class="control-group">
							<div class="control-label">所属校区</div>
							<div class="controls">
								<s:if test="#c == null">
									<select name="campus">
										<s:iterator value="campuses" var="t">
											<option value="${t.id}">${t.name}</option>
										</s:iterator>
									</select>
								</s:if>
								<s:else>
									<input type="text" value="${c.name}" readonly="readonly" />
									<input type="hidden" name="campus" value="${c.id}" />
								</s:else>
							</div>
						</div>
					</fieldset>
					<div class="control-group">
						<div class="controls">
							<button class="btn btn-primary" type="submit">创建</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</tiles:putAttribute>
</tiles:insertDefinition>